<?php

class Application_Model_dataDAO_ChiTietPhietDatHangDAO extends Zend_Db_Table_Abstract implements Application_Model_dataDAOInf_ChiTietPhieuDatHangDAOInf {
	protected $_name = "tb_chitietphieudathang";
	protected static $_instance = null;
	
	public static function getInstance() {
		if (self::$_instance == null) {
			self::$_instance = new self ();
		}
		return self::$_instance;
	}
	/**
	 * @param unknown_type $idPhieuDatHang
	 */
	public function getAllChiTietPhieuDatHang($idPhieuDatHang) {
		$chiTietPhieuDatHang = array ();
		
		try {
			$db = Application_Model_dataDAO_DBConnect::conn ();
			$statement = "SELECT * FROM tb_chitietphieudathang where maPhieuDatHang=" . $idPhieuDatHang;
			$result = $db->fetchAll ( $statement );
			if (count ( $result > 0 )) {
				$i = 0;
				foreach ( $result as $value ) {
					$tenSanPham = $value ['tenSanPham'];
					$donGia = $value ['donGia'];
					$soLuong = $value ['soLuong'];
					$thanhTien = $value ['thanhTien'];
					$chiTiet = new Application_Model_bean_ChiTietPhieuDatHang ();
					$chiTiet->setTenSanPham ( $tenSanPham );
					$chiTiet->setDonGia ( $donGia );
					$chiTiet->setSoLuong ( $soLuong );
					$chiTiet->setThanhTien ( $thanhTien );
					$chiTietPhieuDatHang [$i] = $chiTiet;
					$i ++;
				}
			}
		} catch ( Zend_Db_Exception $e ) {
			echo $e->getMessage ();
		}
		return $chiTietPhieuDatHang;
	
	}
	/**
	 * @param unknown_type $tenSanPham
	 * @param unknown_type $donGia
	 * @param unknown_type $soLuong
	 * @param unknown_type $thanhTien
	 * @param unknown_type $maSanPham
	 * @param unknown_type $maPhieuDatHang
	 */
	public function themChiTietPhieuDatHang($tenSanPham, $donGia, $soLuong, $thanhTien, $maSanPham, $maPhieuDatHang) {
		$result = 0;
		try {
			$db = Application_Model_dataDAO_DBConnect::conn ();
			$data = array ("tenSanPham" => $tenSanPham, "donGia" => $donGia, "soLuong" => $soLuong, "thanhTien" => $thanhTien, "maSanPham" => $maSanPham, "maPhieuDatHang" => $maPhieuDatHang );
			$db->insert( 'tb_chitietphieudathang', $data );
			$result=$db->lastInsertId();
			$db->closeConnection();
		} catch ( Zend_Db_Exception $e ) {
			echo $e->getMessage ();
		}
		return $result;
	}

}

?>